﻿using Newtonsoft.Json;
using ShareRss.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ShareRss
{
    public partial class ChangeConfig : Form
    {
        public ChangeConfig()
        {
            InitializeComponent();
        }

        private void ChangeConfig_Load(object sender, EventArgs e)
        {
            string subtitle = ConfigDll.GetConfigValue("Subtitle");
            var list = JsonConvert.DeserializeObject<List<KeyValueModel>>(subtitle);
            SubtitleCom.DataSource = list;
            SubtitleCom.DisplayMember = "Value";
            SubtitleCom.ValueMember = "Key";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var name = Name.Text.Trim();
            var subId = SubtitleCom.SelectedValue;
            var configText = ConfigDll.GetConfigValue("LoveList");
            if (!string.IsNullOrEmpty(configText)) { ConfigDll.SetConfigValue("LoveList", configText + $"@{subId}_{name}"); }
            else { ConfigDll.SetConfigValue("LoveList", $"{subId}_{name}"); }

            this.Close();
        }

        private void ChangeConfig_FormClosed(object sender, FormClosedEventArgs e)
        {
            MainWindow.mainwindow.ReadLoveList();
        }
    }
}
